//
//  OrderChoosePayView.swift
//  LeGou
//
//  Created by lxm on 2022/8/6.
//

import UIKit

class AuctionResiduePay: XMBaseView {

    //MARK: --------------------属性--------------------
    var disposeBag = DisposeBag()
    
    var selectType = ZMUtil.fastNilBehavior(type: EnumPayTool.self)
    //MARK: --------------------UI控件--------------------
    @IBOutlet weak var content: UIView!

    @IBOutlet weak var wechat: UIButton!
    
    @IBOutlet weak var zfb: UIButton!

    @IBOutlet weak var money: UILabel!
    @IBOutlet weak var needLabel: UILabel!
    @IBOutlet weak var currentLabel: UILabel!
    
    // 支付事件
    var onPayCallback : ((_ tool : EnumPayTool) -> ())?
    
    @IBOutlet weak var sureBtn: UIButton!
    
    let loading = XMLoadingView()

    //MARK: --------------------生命周期--------------------
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        bindAction()
        addConstraints()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        bindAction()
        addConstraints()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        ZMUtil.clipCircle(view: content, Corner: [.topLeft, .topRight], radius: 12)
    }

    //MARK: --------------------UI--------------------
    func setUI() {
        
    }
    
    func addConstraints() {
     
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        selectType.subscribe(onNext:{ [unowned self] resp in
            guard let resp = resp else {
                self.wechat.isSelected = false
                self.zfb.isSelected    = false
                return
            }
            self.wechat.isSelected = resp == .wechat
            self.zfb.isSelected    = resp == .alipay
        }).disposed(by: disposeBag)
    }
    
    @IBAction func onPayTool(_ sender: UIButton) {
        let index = sender.tag - 100
        guard let state = EnumPayTool.init(rawValue: index) else {
            return
        }
        self.selectType.accept(state)
    }
    
    @IBAction func onPay(_ sender: Any) {
        guard let selectType = selectType.value else {
            ZMToast.showToast(title: "请选择一种支付方式")
            return
        }
        if let onPayCallback = onPayCallback {
            onPayCallback(selectType)
        }
    }
    
    @IBAction func onClose(_ sender: Any) {
        removeFromSuperview()
    }
    //MARK: --------------------delegate--------------------

}

